New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

smooth-scrollbar

Package Overview
Dependencies
Maintainers
1
Versions
147
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

smooth-scrollbar

Customize scrollbar in modern browsers with smooth scrolling experience.

  • 3.1.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

smooth-scrollbar

npm npm devDependency Status npm Travis

Customize scrollbar in modern browsers with smooth scrolling experience.

Browser Compatibility

BrowserVersion
IE10+
Chrome22+
Firefox16+
Safari8+
Android Browser4+
Chrome for Android32+
iOS Safarri7+

Install

Via npm:

npm install smooth-scrollbar --save

Via bower:

bower install smooth-scrollbar --save

Demo

http://idiotwu.github.io/smooth-scrollbar/

Why is native scrolling slow?

As is explained in this article, browser repaint every frame in scrolling. Less painting is better.

To avoid repainting, I use translate3d in scroll content to create composite layers and force hardware accelerating.

Usage

Smooth scrollbar is defined as an UMD module which named Scrollbar, you can use any loader to load it:

import Scrollbar from 'smooth-scrollbar';

Or get it from window object:

const { Scrollbar } = window;

Don't forget to include the stylesheet in your page:

<link rel="stylesheet" href="dist/smooth-scrollbar.css">

Here's three way to tell the plugin which element should be a smooth scrollbar:

  1. As an element:

    <scrollbar>
        ...
    </scrollbar>
    
  2. As an attribute:

    <section scrollbar>
        ...
    </section>
    
  3. As a data attribute

    <section data-scrollbar>
        ...
    </section>
    

Then init all scrollbars:

Scrollbar.initAll(options);

Or you can call Scrollbar.init(elem, options) to manually init the scrollbar.

Available Options for Scrollbar

parametertypedefaultdescription
speedNumber1Scrolling speed scale.
frictonNumber10Scrolling fricton, a percentage value within (1, 100)
inflectionNumber10When scrolling speed is lower than infleciton point, sensitivity will be scaled to 10x.
sensitivityNumber0.1Wheel sensitivity, lower is accurate.

Confusing with the option field? Try editor tool here!

DOM Structure

Following is the DOM structure that Scrollbar generated:

<scrollbar>
    <article class="scroll-content">
        your content here
    </article>
    <aside class="scrollbar-track scrollbar-track-x">
        <div class="scrollbar-thumb scrollbar-thumb-x"></div>
    </aside>
    <aside class="scrollbar-track scrollbar-track-y">
        <div class="scrollbar-thumb scrollbar-thumb-y"></div>
    </aside>
</scrollbar>

APIs

Scrollbar

Instance

Work with RubaXa/Sortable

Details here.

Todo

  1. text selection with scrolling on touch screens.

License

MIT.

Keywords

FAQs

Package last updated on 25 Feb 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc